package com.chinairi.mall.controller;


import com.chinairi.common.utils.ResponseUtil;
import com.chinairi.mall.controller.viewobject.ApproveDbIdVO;
import com.chinairi.mall.controller.viewobject.GoodsInfoVO;
import com.chinairi.mall.controller.viewobject.GoodsInforExVO;
import com.chinairi.mall.controller.viewobject.ServiceShelfVO;
import com.chinairi.mall.model.GoodsInfo;
import com.chinairi.mall.model.ServiceShelf;
import com.chinairi.mall.service.IGoodsInfoService;
import com.chinairi.mall.service.IServiceShelfService;
import com.chinairi.mall.service.modelobject.HomeGoodsMO;
import com.chinairi.mall.service.modelobject.HomeServiceMO;
import com.chinairi.mall.service.modelobject.ServiceShelfMO;
import com.chinairi.mall.service.modelobject.ServiceTypeShopMO;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.bind.annotation.RestController;
import com.chinairi.common.controller.BaseController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 五大服务上架功能以及服务商对服务的维护功能， 前端控制器
 * </p>
 *
 * @author Webgasd
 * @since 2020-09-16
 */
@RestController
@RequestMapping("/service-shelf")
public class ServiceShelfController extends BaseController {
    @Autowired
    private IServiceShelfService iServiceShelfService;
    @Autowired
    private IGoodsInfoService iGoodsInfoService;

    /**
     * 获取商品列表
     *
     * @param request 搜索体
     */
    @GetMapping("/getList")
    public void getList(String type, HttpServletRequest request) throws IOException {
        String csDbId = iGoodsInfoService.getCsDbid(type, request);
        ServiceShelf serviceShelf = new ServiceShelf();
        serviceShelf.setCsDbid(csDbId);
        List<ServiceShelf> list = iServiceShelfService.getListByCsDbId(serviceShelf);
        GoodsInforExVO goodsInforExVO = new GoodsInforExVO();
        goodsInforExVO.setCsDbid(csDbId);
        goodsInforExVO.setServiceShelfList(list);
        ResponseUtil.showMessage("success", "获取成功", goodsInforExVO);
    }

    /**
     * 根据商品id获取商品信息
     *
     * @param serviceDbId 服务产品主键
     * @throws IOException 异常
     */
    @GetMapping("/getByDbid")
    public void getByDbid(String serviceDbId) throws IOException {
        ServiceShelfVO serviceShelfVO = iServiceShelfService.getByDbId(serviceDbId);
        ResponseUtil.showMessage("success", "获取成功", serviceShelfVO);
    }


    @PostMapping("/add")
    public void add(@RequestBody ServiceShelfVO serviceShelfVO) throws IOException {
        iServiceShelfService.add(serviceShelfVO);
        ResponseUtil.showMessage("success", "获取成功", null);
    }

    @PostMapping("/update")
    public void update(@RequestBody ServiceShelfVO serviceShelfVO) throws IOException {
        iServiceShelfService.updateAll(serviceShelfVO);
        ResponseUtil.showMessage("success", "获取成功", null);
    }

    @GetMapping("/getServiceInfoListByCsDbIdList")
    public void getServiceInfoListByCsDbIdList(String serviceType, String serviceClass) throws IOException {
        Map<String, List<ServiceTypeShopMO>> resultMap = iServiceShelfService.getMap(serviceType,serviceClass);
        ResponseUtil.showMessage("success", "获取成功", resultMap);
    }

    /**
     * 批量提交服务商品审核
     * @param approveDbIdVoList
     * @throws IOException
     */
    @PostMapping("/updateStatus")
    public void updateStatus(@RequestBody List<ApproveDbIdVO> approveDbIdVoList) throws IOException {
        iServiceShelfService.updateStatus(approveDbIdVoList);
        ResponseUtil.showMessage("success", "添加审核成功", null);
    }

    /**
     * 服务商品搜索列表
     * 搜索项
     * csDbid               精确搜索   店铺id
     * ssServiceTypeDbid    精确搜索   服务大类编码
     * ssServiceTypeName    模糊搜索   服务大类名称
     * ssServiceClassDbid   精确搜索   服务小类编码
     * ssServiceClassName   模糊搜索   服务小类名称
     * @param homeServiceMo
     * @throws IOException
     */
    @GetMapping("/getHomeService")
    public void getHomeService(HomeServiceMO homeServiceMo) throws IOException {
        List<HomeServiceMO> homeServiceMOList = iServiceShelfService.getHomeService(homeServiceMo);
        ResponseUtil.showMessage("success", "获取成功", homeServiceMOList);
    }

    /**
     * 删除服务
     * @param serviceDbid
     * @throws IOException
     */
    @DeleteMapping("/deleteById")
    public void deleteById(@RequestParam("serviceDbid") String serviceDbid) throws IOException {
        iServiceShelfService.deleteById(serviceDbid);
        ResponseUtil.showMessage("success", "删除服务成功", "");
    }

    /**
     * 获取用户须知
     * @param serviceType 服务大类id
     * @param serviceClassIds 服务小类id
     * @throws IOException e
     */
    @GetMapping("/getNoticeByCsId")
    @ResponseBody
    public void getNoticeByCsId(String serviceType, @RequestParam List<String> serviceClassIds) throws IOException {
        List<ServiceShelf> serviceShelves = iServiceShelfService.getNoticeByCsId(serviceType,serviceClassIds);
        ResponseUtil.showMessage("success","获取服务须知成功",serviceShelves);
    }

    /**
     * 获取收费标准
     * @param serviceType 服务大类id
     * @param serviceClassIds 服务小类id
     * @throws IOException e
     */
    @GetMapping("/getPriceRuleByCsId")
    @ResponseBody
    public void getPriceRuleByCsId(String serviceType, @RequestParam List<String> serviceClassIds) throws IOException {
        List<ServiceShelf> serviceShelves = iServiceShelfService.getPriceRuleByCsId(serviceType, serviceClassIds);
        ResponseUtil.showMessage("success","获取收费标准成功",serviceShelves);
    }
}
